/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.umlviewer.view;

import java.awt.Color;
import java.awt.Frame;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import org.umlviewer.model.VisibilityKind;
import org.umlviewer.model.diagram_class.Attribute;
import org.umlviewer.model.diagram_class.Clase;
import org.umlviewer.model.diagram_class.Method;
import org.umlviewer.model.diagram_class.Param;


/**
 *
 * @author Rafa
 */
public class ClassProperty extends javax.swing.JDialog implements ParametersEdit{

    /**
     * Creates new form ClassProperty
     */
    Clase _class;
    Frame parent;
    DefaultTableModel tableAttribModel;
    DefaultTableModel tableMethodModel;
    JTable tblAttributes, tblMethods;
    String titulos[] = {"Nombre","Tipo"};
    ArrayList<Attribute> attributes;
    ArrayList<Method> methods;
    ArrayList<Param> params;
    private Color selectedColor;
    private Attribute editAtt=null;
    private Method editMet = null;
    private int editRow = -1;
    private int mEditRow = -1;
    
    public ClassProperty(java.awt.Frame parent, boolean modal, Clase c) {
        super(parent, modal);
        this.parent  = parent;
        initComponents();
        txtClassName.setText(c.getName());
        this._class = c;   
        tableAttribModel = new DefaultTableModel(titulos, 0);
        tableMethodModel = new DefaultTableModel(titulos,0);
        tblAttributes = new JTable(tableAttribModel){public boolean isCellEditable(int row,int col){return false;}};       
        tblMethods = new JTable(tableMethodModel){public boolean isCellEditable(int row,int col){return false;}};;
        
        jScrollPane1.setViewportView(tblAttributes);
        jScrollPane2.setViewportView(tblMethods);
        
        setTitle("Propiedades: "+_class.getName());
        txtFillColor.setBackground(_class.getFillColor());
        txtLineColor.setBackground(_class.getLineColor());
        //atributos
        attributes = _class.getAttributes();
        if(!attributes.isEmpty())
        {
            for(Attribute a : attributes)
            {
                Object[] row = new Object[2];
                row[0] = a.getName();
                row[1] = a.getType();
                tableAttribModel.addRow(row);    
            }            
        }
        //metodos
        methods = _class.getMethods();
        if(!methods.isEmpty()){
            for(Method m: methods){
                Object[] row = new Object[2];
                row[0] = m.getName();
                row[1] = m.getType();
                tableMethodModel.addRow(row);
            }
        }
        chkAbstract.setSelected(_class.isbAstract());
        //change combobox model to use Visibility Enum Values
        cboAttVisibility.setModel(new DefaultComboBoxModel(VisibilityKind.values()));
        cboMethodVis.setModel(new DefaultComboBoxModel(VisibilityKind.values()));
        //evento al seleccionar fila
        tblAttributes.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent event) {
                tblAttributesValueChanged(event);
            }
        });
        tblMethods.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent event) {
                tblMethodsValueChanged(event);
            }
        });
        txtClassName.requestFocus();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtClassName = new javax.swing.JTextField();
        lblAbstract = new javax.swing.JLabel();
        chkAbstract = new javax.swing.JCheckBox();
        jPanel4 = new javax.swing.JPanel();
        txtLineColor = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtFillColor = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        txtAttName = new javax.swing.JTextField();
        lblAttribName = new javax.swing.JLabel();
        txtAttType = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cboAttVisibility = new javax.swing.JComboBox();
        chkAttStatic = new javax.swing.JCheckBox();
        jButton5 = new javax.swing.JButton();
        btnNewAtt = new javax.swing.JButton();
        btnSaveAtt = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtMethodName = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtMethodParams = new javax.swing.JTextField();
        btnParamsDetail = new javax.swing.JButton();
        txtMethodRet = new javax.swing.JTextField();
        cboMethodVis = new javax.swing.JComboBox();
        chkMethodStatic = new javax.swing.JCheckBox();
        chkMethodAbstract = new javax.swing.JCheckBox();
        btnMetNew = new javax.swing.JButton();
        btnMetSave = new javax.swing.JButton();
        btnMetDelete = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Propiedades");

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Nombre:");

        txtClassName.setText("jTextField1");

        lblAbstract.setText("Abstracta:");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Apariencia"));

        txtLineColor.setBackground(new java.awt.Color(255, 0, 51));
        txtLineColor.setEnabled(false);
        txtLineColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtLineColorMouseClicked(evt);
            }
        });
        txtLineColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtLineColorActionPerformed(evt);
            }
        });

        jLabel6.setText("Color de relleno:");

        txtFillColor.setEnabled(false);
        txtFillColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtFillColorMouseClicked(evt);
            }
        });
        txtFillColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFillColorActionPerformed(evt);
            }
        });

        jLabel5.setText("Color de linea: ");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtFillColor, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtLineColor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtFillColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtLineColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 42, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(lblAbstract))
                        .addGap(63, 63, 63)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtClassName, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(chkAbstract)))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(151, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtClassName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(chkAbstract)
                    .addComponent(lblAbstract))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(226, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("General", jPanel1);

        jLabel4.setText("Atributos");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblAttribName.setText("Nombre:");

        jLabel3.setText("Visibilidad:");

        jLabel2.setText("Tipo:");

        chkAttStatic.setText("Estatico");

        jButton5.setText("Eliminar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        btnNewAtt.setText("Nuevo");
        btnNewAtt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewAttActionPerformed(evt);
            }
        });

        btnSaveAtt.setText("Guardar");
        btnSaveAtt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveAttActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblAttribName, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cboAttVisibility, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtAttName, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtAttType, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(79, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnNewAtt)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSaveAtt)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5)
                        .addGap(30, 30, 30))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(chkAttStatic)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAttribName)
                    .addComponent(txtAttName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtAttType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cboAttVisibility, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkAttStatic)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSaveAtt)
                    .addComponent(btnNewAtt)
                    .addComponent(jButton5))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Atributos", jPanel2);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel7.setText("Nombre:");

        jLabel8.setText("Parametros:");

        jLabel9.setText("Tipo de retorno:");

        jLabel10.setText("Visibilidad:");

        btnParamsDetail.setText("...");
        btnParamsDetail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnParamsDetailActionPerformed(evt);
            }
        });

        chkMethodStatic.setText("Estatico");

        chkMethodAbstract.setText("Abstracto");
        chkMethodAbstract.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkMethodAbstractActionPerformed(evt);
            }
        });

        btnMetNew.setText("Nuevo");
        btnMetNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMetNewActionPerformed(evt);
            }
        });

        btnMetSave.setText("Guardar");
        btnMetSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMetSaveActionPerformed(evt);
            }
        });

        btnMetDelete.setText("Eliminar");
        btnMetDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMetDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(chkMethodAbstract)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(chkMethodStatic)
                        .addContainerGap())
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addGap(46, 46, 46)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtMethodParams, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                                    .addComponent(txtMethodName))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                                .addComponent(btnParamsDetail, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtMethodRet)
                                    .addComponent(cboMethodVis, 0, 146, Short.MAX_VALUE))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap(28, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnMetNew)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnMetSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnMetDelete))))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtMethodName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtMethodParams, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnParamsDetail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtMethodRet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(cboMethodVis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkMethodStatic)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(chkMethodAbstract)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnMetNew)
                    .addComponent(btnMetSave)
                    .addComponent(btnMetDelete))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jLabel11.setText("Operaciones");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Metodos", jPanel5);

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        _class.setRefresh(true);
        _class.setName(txtClassName.getText());
        _class.setFillColor(txtFillColor.getBackground());
        _class.setLineColor(txtLineColor.getBackground());
        _class.setAbstract(chkAbstract.isSelected());        
        this.dispose();        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnSaveAttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveAttActionPerformed
        Attribute att;
        if(editAtt!=null && editRow >=0)
            att = editAtt;
        else
            att= new Attribute();
        att.setName(txtAttName.getText());
        att.setType(txtAttType.getText());
        att.setVisibility((VisibilityKind)cboAttVisibility.getSelectedItem());
        att.setStatic(chkAttStatic.isSelected());
        if(editAtt!=null){
            tableAttribModel.setValueAt(editAtt.getName(), editRow, 0);
            tableAttribModel.setValueAt(editAtt.getType(), editRow, 1);
            editRow = -1;
            editAtt =null;
        }else{        
            Object[] row = new Object[2];
            row[0] = att.getName();
            row[1] = att.getType();
            tableAttribModel.addRow(row);
            _class.addAttribute(att);
        }
        clearAttribFields();
    }//GEN-LAST:event_btnSaveAttActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void txtLineColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtLineColorMouseClicked
        selectedColor = JColorChooser.showDialog(this, "Seleccionar color", txtLineColor.getBackground());
        txtLineColor.setBackground(selectedColor);
    }//GEN-LAST:event_txtLineColorMouseClicked

    private void txtLineColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtLineColorActionPerformed
        // TODO add your handling code here:

   }//GEN-LAST:event_txtLineColorActionPerformed

    private void txtFillColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtFillColorMouseClicked
        // TODO add your handling code here:
        selectedColor = JColorChooser.showDialog(this, "Seleccionar color", txtFillColor.getBackground());
        if(selectedColor!=null)
            txtFillColor.setBackground(selectedColor);
    }//GEN-LAST:event_txtFillColorMouseClicked

    private void txtFillColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFillColorActionPerformed
        // TODO add your handling code here:

   }//GEN-LAST:event_txtFillColorActionPerformed

    private void chkMethodAbstractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkMethodAbstractActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_chkMethodAbstractActionPerformed

    private void btnMetSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMetSaveActionPerformed
        //guardar / editar un metodo
        Method m;
        if(editMet!=null && mEditRow>=0)
            m = editMet;
        else
            m= new Method();
        m.setName(txtMethodName.getText());
        m.setType(txtMethodRet.getText());
        m.setStatic(chkMethodStatic.isSelected());
        m.setAbstrac(chkMethodAbstract.isSelected());
        m.setVisibility((VisibilityKind)cboMethodVis.getSelectedItem()); 
        if(params!=null)
            m.setParams(params);
        if(editMet!=null){
            tableMethodModel.setValueAt(editMet.getName(), mEditRow, 0);
            tableMethodModel.setValueAt(editMet.getType(), mEditRow, 1);
            editMet = null;
            mEditRow = -1;
        }else{
            Object row[] = new Object[2];
            row[0] = m.getName();
            row[1] = m.getType();
            tableMethodModel.addRow(row);
            _class.addMethod(m);
        }
        clearMethodFields();
    }//GEN-LAST:event_btnMetSaveActionPerformed

    private void btnParamsDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnParamsDetailActionPerformed
        ParametersProperty paramView;
        if(editMet!=null)
            paramView= new ParametersProperty(null, true, editMet,this);
        else
            paramView= new ParametersProperty(null, true, null,this);
        paramView.setVisible(true);
    }//GEN-LAST:event_btnParamsDetailActionPerformed

    private void btnMetDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMetDeleteActionPerformed
        if(tblMethods.getSelectedRow()>=0){
            methods.remove(tblMethods.getSelectedRow());
            tableMethodModel.removeRow(tblMethods.getSelectedRow());
        }
    }//GEN-LAST:event_btnMetDeleteActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        int selRow = tblAttributes.getSelectedRow();
        if(selRow >= 0){
            attributes.remove(selRow);
            tableAttribModel.removeRow(selRow);            
            clearAttribFields();
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void btnNewAttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewAttActionPerformed
        clearAttribFields();
        editRow = -1;
        editAtt =null;
    }//GEN-LAST:event_btnNewAttActionPerformed

    private void btnMetNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMetNewActionPerformed
        clearMethodFields();
        editMet = null;
        mEditRow = -1;
    }//GEN-LAST:event_btnMetNewActionPerformed

     private void tblAttributesValueChanged(ListSelectionEvent event) {
        editRow = tblAttributes.getSelectedRow();
        if(editRow>=0){ //evitar errores al eliminar elementos
            editAtt = attributes.get(editRow);
            txtAttName.setText(editAtt.getName());
            txtAttType.setText(editAtt.getType());
            cboAttVisibility.setSelectedItem(editAtt.getVisibility());
            chkAttStatic.setSelected(editAtt.isStatic());
        }
     }
    
     private void tblMethodsValueChanged(ListSelectionEvent event){
         mEditRow = tblMethods.getSelectedRow();
         if(mEditRow >=0 ){
             editMet = methods.get(mEditRow);
             txtMethodName.setText(editMet.getName());
             txtMethodRet.setText(editMet.getType());
             cboMethodVis.setSelectedItem(editMet.getVisibility());
             chkMethodAbstract.setSelected(editMet.isAbstrac());
             chkMethodStatic.setSelected(editMet.isStatic());             
             setParameters(editMet.getParams());
         }
     }
     
    //asignar parametros que vienen de la ventana de parametros
    @Override
    public void setParameters(ArrayList<Param> parameters){
        this.params = parameters;
        String txt = "";
        //mostrar los parametros en el txt
        for(Param p : parameters){
            txt += p.getType()+",";            
        }
        txtMethodParams.setText(txt);
    }
    
    private void clearAttribFields(){
        txtAttName.setText("");
        txtAttType.setText("");
        chkAttStatic.setSelected(false);
        cboAttVisibility.setSelectedIndex(0);
    }
    
    private void clearMethodFields(){
        txtMethodName.setText("");
        txtMethodRet.setText("");
        chkMethodAbstract.setSelected(false);
        chkMethodStatic.setSelected(false);
        cboMethodVis.setSelectedIndex(0);
        txtMethodParams.setText("");
        this.params = null;
    }

    /**
     * @param args the command line arguments
     */    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnMetDelete;
    private javax.swing.JButton btnMetNew;
    private javax.swing.JButton btnMetSave;
    private javax.swing.JButton btnNewAtt;
    private javax.swing.JButton btnParamsDetail;
    private javax.swing.JButton btnSaveAtt;
    private javax.swing.JComboBox cboAttVisibility;
    private javax.swing.JComboBox cboMethodVis;
    private javax.swing.JCheckBox chkAbstract;
    private javax.swing.JCheckBox chkAttStatic;
    private javax.swing.JCheckBox chkMethodAbstract;
    private javax.swing.JCheckBox chkMethodStatic;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblAbstract;
    private javax.swing.JLabel lblAttribName;
    private javax.swing.JTextField txtAttName;
    private javax.swing.JTextField txtAttType;
    private javax.swing.JTextField txtClassName;
    private javax.swing.JTextField txtFillColor;
    private javax.swing.JTextField txtLineColor;
    private javax.swing.JTextField txtMethodName;
    private javax.swing.JTextField txtMethodParams;
    private javax.swing.JTextField txtMethodRet;
    // End of variables declaration//GEN-END:variables
}
